using System;
using System.Collections.Generic;
using System.Globalization;
using Unity.Environment;
using Xunit;

namespace Unity.Commons.Tests
{
    public class UnityEnvironmentTest
    {
        [Fact]
        public void InitializeCurrentEnvironmentTest()
        {
            List<KeyValuePair<string, string>> currentParameters = 
                new List<KeyValuePair<string, string>>
                (UnityEnvironment.GetAllCurrentEnvironmentParameters());
            Assert.True(currentParameters.Count > 0);
        }

        [Fact]
        public void ModifyCurrentEnvironmentParametersTest()
        {
            string testEnvBoolParamName = "UnityTestBoolParam";
            string testEnvIntParamName = "UnityTestIntParam";
            string testEnvDoubleParamName = "UnityTestDoubleParam";
            string testEnvStringParamName = "UnityTestStringParam";

            bool   testEnvBoolParamValue = false;
            int    testEnvIntParamValue = 123;
            double testEnvDoubleParamValue = 123.456;
            string testEnvStringParamValue = "Example";

            UnityEnvironment.SetCurrentEnvironmentParameter(testEnvBoolParamName, testEnvBoolParamValue.ToString(CultureInfo.InvariantCulture));
            UnityEnvironment.SetCurrentEnvironmentParameter(testEnvIntParamName, testEnvIntParamValue.ToString(CultureInfo.InvariantCulture));
            UnityEnvironment.SetCurrentEnvironmentParameter(testEnvDoubleParamName, testEnvDoubleParamValue.ToString(CultureInfo.InvariantCulture));
            UnityEnvironment.SetCurrentEnvironmentParameter(testEnvStringParamName, testEnvStringParamValue.ToString(CultureInfo.InvariantCulture));

            var returnEnvBoolParamValue = UnityEnvironment.GetBoolParameter(testEnvBoolParamName);
            var returnEnvIntParamValue = UnityEnvironment.GetIntegerParameter(testEnvIntParamName);
            var returnEnvDoubleParamValue = UnityEnvironment.GetDoubleParameter(testEnvDoubleParamName);
            var returnEnvStringParamValue = UnityEnvironment.GetStringParameter(testEnvStringParamName);

            Assert.Equal(testEnvBoolParamValue, returnEnvBoolParamValue);
            Assert.Equal(testEnvIntParamValue, returnEnvIntParamValue);
            Assert.Equal(testEnvDoubleParamValue, returnEnvDoubleParamValue);
            Assert.Equal(testEnvStringParamValue, returnEnvStringParamValue);
        }
    }
}
